package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.ExamResult;
import com.hwadee.teachingprocessmanagementsystem.dao.ExamResultDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ExamResultService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

import java.util.List;

/**
 * 考试成绩表(ExamResult)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("examResultService")
public class ExamResultServiceImpl implements ExamResultService {
    @Resource
    private ExamResultDao examResultDao;

    /**
     * 通过ID查询单条数据
     *
     * @param resultId 主键
     * @return 实例对象
     */
    @Override
    public ExamResult queryById(Integer resultId) {
        return this.examResultDao.queryById(resultId);
    }

    public List<ExamResult> queryByExamId(Integer examId){
        return this.examResultDao.queryByExamId(examId);
    }



    /**
     * 分页查询
     *
     * @param examResult 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ExamResult> queryByPage(ExamResult examResult, PageRequest pageRequest) {
        long total = this.examResultDao.count(examResult);
        return new PageImpl<>(this.examResultDao.queryAllByLimit(examResult, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param examResult 实例对象
     * @return 实例对象
     */
    @Override
    public ExamResult insert(ExamResult examResult) {
        this.examResultDao.insert(examResult);
        return examResult;
    }

    /**
     * 修改数据
     *
     * @param examResult 实例对象
     * @return 实例对象
     */
    @Override
    public ExamResult update(ExamResult examResult) {
        this.examResultDao.update(examResult);
        return this.queryById(examResult.getResultId());
    }

    /**
     * 通过主键删除数据
     *
     * @param resultId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer resultId) {
        return this.examResultDao.deleteById(resultId) > 0;
    }

    @Override
    public List<ExamResult> queryByStudentNumber(String studentNumber) {
        return this.examResultDao.queryByStudentNumber(studentNumber);
    }
}
